package com.example.qjia.model;

import android.util.Log;

import com.example.qjia.Listener.RegisterListener;
import com.example.qjia.data.romotedata.Result;
import com.example.qjia.data.romotedata.person;
import com.example.qjia.util.retrofit.RetrofitNet;

import java.util.logging.Handler;

import rx.Observer;

/**
 * Created by ying_xiang on 2016/8/17.
 */
public class RegisterModelImp implements RegisterModel {
    private android.os.Handler handler=new android.os.Handler();
    private static final String TAG="RegisterModelImp";

    @Override
    public void registerNewUser(final String studentName, final String pwd, final String studentId, final String studentTel, final String master, final String masterClass, final String acadamy, final String mail, final RegisterListener registerListener) {
        Log.i(TAG, "registerNewUser: "+studentName);
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                new android.os.Handler().postDelayed(new Runnable() {
                    @Override
                    public void run() {

                        new RetrofitNet().register(studentName,pwd,studentId,studentTel,master,masterClass,acadamy,mail,new Observer<Result>() {
                            @Override
                            public void onCompleted() {
                                //完成
                                System.out.println("finish");
                            }

                            @Override
                            public void onError(Throwable e) {
                                //异常
                                System.out.println("error");
                                Log.e("MAIN2",e.getLocalizedMessage()+"--"+e.getMessage());
                            }

                            @Override
                            public void onNext(Result baseBean) {
                                //成功
                                Result p=baseBean;
                                if(p.getCode()==0) {  //注册成功

                                    System.out.println(p.toString());
                                    registerListener.registerSuccess();
                                }else {
                                    registerListener.registerFailed();
                                }


                            }
                        });




                    }
                }, 1000);
            }
        },1000);


    }

}
